﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PhotoEdit.aspx.cs" Inherits="CXedu.WebSite.WebAdmin.PhotoEdit" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="CXedu.Model" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>图集管理</title>
    <link href="/css/admin/admin.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="/js/jquery.js"></script>
    <!--uploadify配置Begin-->
    <link rel="stylesheet" href="/js/uploadify/uploadify.css" />
    <script type="text/javascript" charset="utf-8" src="/js/uploadify/jquery.uploadify.js"></script>
	<script type="text/javascript">
	    $(function () {
	        $('#file_upload').uploadify({
	            'formData': {
	                'cid': '<%=id %>',
	                'uname': '<%=User.Identity.Name %>'
	            },
	            'buttonText': '批量上传图片',
	            'swf': '/js/uploadify/uploadify.swf',
	            'uploader': '/WebAdmin/Ajax/photoimgs.ashx',
	            'onUploadSuccess': function (file, data, response) {
	                var obj = $.parseJSON(data);
	                if (obj.error == 1) {
	                    $("#errorTr").show();
	                    $("#errorInfo").html($("#errorInfo").html() + "[" + file.name + "]：" + obj.message + "<br/>");
	                }
	            },
	            'onQueueComplete': function (queueData) {
	                $("#tipInfo").text("数据处理中.....");
	                setTimeout(function () { window.location.reload(); }, 500);
	            }
	        });
	    });
	    function DelPhotoImg(v) {
	        if (v != null && v != "") {
	            if (!confirm("您确定要删除该图片吗？")) {
	                return;
	            }
	            $.post("/WebAdmin/Ajax/DataAjax.ashx", { act: "DelPhotoImg", Ids: v }, function (msg) {
	                var data = $.parseJSON(msg);
	                if (data.result == "true") {
	                    var uploadnum = $("#uploadnum").html();
	                    if (uploadnum != null && uploadnum != "" && parseInt(uploadnum) != NaN && parseInt(uploadnum) > 0) {
	                        $("#uploadnum").html(parseInt(uploadnum) - 1);
	                    }
	                    $("#img" + v).remove();
	                }
	                else {
	                    alert(data.prompt);
	                }
	            });
	        }
	    }

	    function BatchSavePhotoImgs(id) {
	        if (id != "" && parseInt(id) > 0) {
	            $.post("/WebAdmin/Ajax/DataAjax.ashx", { act: "BatchSavePhotoImgs", Id: id, "Summary": $("#txtTitle_" + id).val(), "Url": $("#txtUrl_" + id).val(), "Sort": $("#txtSort_" + id).val() }, function (msg) {
	                var data = $.parseJSON(msg);
	                if (data.result == "true") {
	                    alert('保存成功');
	                }
	                else {
	                    alert(data.prompt);
	                }
	            });
	        }
	    }
	</script>
    <!--uploadify配置End-->
</head>
<body>
    <div class="titlebt">图集管理</div>
    <div style="padding-left: 100px;">
        <a href="PhotoList.aspx" class="butt_tle" style="width:80px">返回列表</a>
        <a href="javascript:;" class="butt_tle" style="width:80px" onclick="window.location.reload();">刷新</a>
    </div>
    <!--显示列表-->
    <div id="all">
        <div class="k_all3">
            <table width="100%" cellpadding="0" cellspacing="0" id="bk">
                <tbody>
                    <tr>
                        <td colspan="2" align="center">
                            <%
                                switch (id)
                                { 
                                    case 1:
                                        Response.Write("首页广告");
                                        break;
                                    case 2:
                                        Response.Write("医师培训首页广告");
                                        break;
                                }
                                 %>-图集列表<br />
                                 （提示：排序规则为序号小的在前面，序号大的在后面。）
                        </td>
                    </tr>
                    <tr id="errorTr" style="display:none;">
                        <td width="326" height="35" align="right">
                            错误信息：
                        </td>
                        <td width="990">
                            <span id="errorInfo"></span>
                        </td>
                    </tr>
                    <tr>
                        <td width="326" height="35" align="right">
                            批量上传图片：
                        </td>
                        <td width="990">
		                    <input id="file_upload" name="file_upload" type="file" multiple="true"/>
                        </td>
                    </tr>
                    <tr>
                        <td id="tipInfo" colspan="2" align="center">
                            <% 
                                if (photoImgs.Count > 0)
                                {
                                    Response.Write("已上传[<span id='uploadnum'>" + photoImgs.Count + "</span>]张图片");
                                }
                                else
                                {
                                    Response.Write("还未上传图片");
                                }    
                            %>
                        </td>
                    </tr>
                    <% 
                        foreach (PhotoImgs item in photoImgs)
                        {
                    %>
                    <tr id='img<%=item.Id %>'>
                        <td width="100px" align="center">
                            <img id='face<%=item.Id %>' alt="" src='<%=item.SmallSrc %>'/>
                        </td>
                        <td>
                            <table>
                                <tr>
                                    <td width="50px">
                                        简介：
                                    </td>
                                    <td>
                                        <textarea id='txtTitle_<%=item.Id %>' cols="20" rows="3" style="resize:none;width:300px;height:70px"><%=item.Summary%></textarea>
                                    </td>
                                    <td rowspan="3">
                                        <a href="javascript:;" onclick="BatchSavePhotoImgs('<%=item.Id %>')">[保存]</a><br />
                                        <a href="javascript:;" onclick="DelPhotoImg('<%=item.Id %>')">[删除]</a>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        链接：
                                    </td>
                                    <td>
                                        <input id='txtUrl_<%=item.Id %>' type="text" class="wi135" style="width:300px" value="<%=item.LinkUrl %>" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        排序：
                                    </td>
                                    <td>
                                        <input id='txtSort_<%=item.Id %>' type="text" class="wi135" value="<%=item.Sort %>" />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <%
                        }
                    %>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>